# -*- coding: utf-8 -*-

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
from pyLib.AESCipher import AESCipher
import pyLib
import json
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%d/%m/%Y %H:%M:%S')

def encrypt(source):
        cipher = AESCipher("longhoanggiang")
        if not source.endswith("/"): source += "/"
        a = pyLib.gz_file_get_content(source + "data")
        try:
            data = json.loads(a)
            '''
            for item in data:
                path = source + item['path'] + "/data"
                content = pyLib.gz_file_get_content(path)
                content = cipher.encrypt(content)
                pyLib.gz_file_put_content(path, content)
            '''
            cipherText = cipher.encrypt(a)
            pyLib.gz_file_put_content(source + "data", cipherText)
        except:
            logging.warning("already encrypted")
            

            
if __name__ == '__main__':

    source = raw_input("> Enter path: ")
    encrypt(source)
    print '>Finished'
    os._exit(1)